# configdialog.py
# this is a dialog to allow the user to specify the change in difficulty of a card when you get it wrong or right

import sys
from PyQt4 import QtGui, QtCore

class ConfigDialog(QtGui.QDialog):
    def __init__(self, vocab, parent=None):
        QtGui.QDialog.__init__(self, parent)
        
        self.vocab = vocab
        
        self.setWindowTitle('Specify Change in Difficulty')
        self.layout = QtGui.QGridLayout(self)
        changeValidator = QtGui.QDoubleValidator(self)
        changeValidator.setBottom(0)
        self.increment = QtGui.QLineEdit(str(self.vocab.difficultyInc))
        self.increment.setValidator(changeValidator)
        self.increment.setFixedWidth(40)
        self.decrement = QtGui.QLineEdit(str(self.vocab.difficultyDec * -1))
        self.decrement.setValidator(changeValidator)
        self.decrement.setFixedWidth(40)
        
        self.layout.addWidget(QtGui.QLabel('When I click \'I got it wrong\' increase difficulty by', self), 0, 0, 1, 2)
        self.layout.addWidget(self.increment, 0, 2)
        self.layout.addWidget(QtGui.QLabel('When I click \'I got it right\' decrease difficulty by', self), 1, 0, 1, 2)
        self.layout.addWidget(self.decrement, 1, 2)
        
        self.okButton = QtGui.QPushButton('OK', self)
        self.cancelButton = QtGui.QPushButton('Cancel', self)
        row = self.layout.rowCount()
        self.layout.addWidget(self.okButton, row, 0)
        self.layout.addWidget(self.cancelButton, row, 1)
        
        self.connect(self.okButton, QtCore.SIGNAL('clicked()'), self.ok)
        self.connect(self.cancelButton, QtCore.SIGNAL('clicked()'), self.cancel)
    
    def ok(self):
    
        self.vocab.difficultyInc = float(str(self.increment.text()))
        self.vocab.difficultyDec = -1 * float(str(self.decrement.text()))
        self.vocab.changed = True
        self.close()
    
    def cancel(self):
        self.close()
